using System;
using System.Collections.Generic;

using octalforty.Componento.Core.Framework;
using octalforty.Componento.Core.ObjectModel;

using System.Linq;

namespace octalforty.Componento.Core.ApplicationServices
{
    public class PackageResourceProviderService
    {
        private readonly IEnumerable<IPackageResourceProvider> packageResourceProviders;

        public PackageResourceProviderService(IEnumerable<IPackageResourceProvider> packageResourceProviders)
        {
            this.packageResourceProviders = packageResourceProviders;
        }

        public Uri[] GetResourceUris(PackageManifest package, Uri resourceUri)
        {
            var provider = packageResourceProviders.FirstOrDefault(prp => prp.SupportedSchemas.Contains(resourceUri.Scheme.ToLowerInvariant()));

            return provider == null ?
                null :
                provider.GetResourceUris(package, resourceUri);
        }
    }
}